package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsOrderGoods;
import com.qf.service.DtsOrderGoodsService;
import com.qf.service.DtsOrderService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import com.qf.vo.ChannelVo;
import com.qf.vo.StatVo;
import com.qf.vo.UserVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Zwnan
 */
@RestController
@RequestMapping("/admin/order")
@CrossOrigin
public class OrderController {
    @Autowired
    private DtsOrderService dtsOrderService;
    @RequiresPermissionsDesc(menu = {"商场管理","订单管理"},button ="查找")
    @RequiresPermissions("admin:order:list")
    @GetMapping("/list")
    public Object orderList(@RequestParam(defaultValue = "1")Integer page,
                            @RequestParam(defaultValue = "20") Integer limit,
                            @RequestParam(defaultValue = "add_time") String sort,
                            @RequestParam(defaultValue = "desc") String order){

        IPage<DtsOrder> iPage = dtsOrderService.findPage(page,limit,sort,order);
        long total = iPage.getTotal();
        List<DtsOrder> records = iPage.getRecords();
        Map map = new HashMap();
        map.put("total", total);
        map.put("items", records);
        return ResponseUtil.ok(map);
    }

    @GetMapping("/listShipChannel")
    public Object listShipChannel(@RequestParam(defaultValue = "1")Integer page,
                            @RequestParam(defaultValue = "20") Integer limit,
                            @RequestParam(defaultValue = "add_time") String sort,
                            @RequestParam(defaultValue = "desc") String order){

        List<ChannelVo> list = new ArrayList<>();
        list.add(new ChannelVo("HTKY","百世快递"));
        list.add(new ChannelVo("ZTO","中通快递"));
        list.add(new ChannelVo("YTO","圆通速递"));
        list.add(new ChannelVo("YD","韵达速递"));

        return ResponseUtil.ok(list);
    }

    @Autowired
    private DtsOrderGoodsService dtsOrderGoodsService;
    @Autowired
    private DtsUserService dtsUserService;
    @GetMapping("/detail")
    public Object detail(Integer id){

        List<DtsOrderGoods> OrderGoods = dtsOrderGoodsService.findById(id);

        Integer userId = dtsOrderService.selectById(id);
        UserVo userVo = dtsUserService.findByOrderId(userId);

        DtsOrder dtsOrder = dtsOrderService.findById(id);

        Map map = new HashMap();
        map.put("orderGoods",OrderGoods);
        map.put("user", userVo);
        map.put("order",dtsOrder);

        return ResponseUtil.ok(map);
    }



}
